﻿using System.Globalization;
using System.Windows;
using System.Windows.Markup;
using Acme.Business;
using Acme.Common.Services;
using Microsoft.Practices.Unity;

namespace Acme.MVVM.IOC
{

    public partial class App : Application
    {

        protected override void OnStartup(StartupEventArgs e)
        {

            // Ensure the current culture passed into bindings 
            // is the OS culture. By default, WPF uses en-US 
            // as the culture, regardless of the system settings.

            FrameworkElement.LanguageProperty.OverrideMetadata(
              typeof(FrameworkElement),
              new FrameworkPropertyMetadata(
                  XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

            IUnityContainer container = new UnityContainer();

            container.RegisterType<IDialogService, ModalDialogService>(new ContainerControlledLifetimeManager());
            container.RegisterType<IEventRepository, EventRepository>(new ContainerControlledLifetimeManager());

            MainWindow window = container.Resolve<MainWindow>();
            window.DataContext = container.Resolve<MainWindowViewModel>();
            window.Show();
        }
    }
}